import ToolRequest from '@/base/newToolAxios'
import RequestOption from '@/base/RequestOption'
import { getActToolUrl } from '@/base/constant'
const tr = new ToolRequest()

export default class DishDao {
    /**
     * 列出所有菜品
     * @returns
     */
    async listAll(){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'listAll'
        }, ro)
    }

    /**
     * 根据类别和状态筛选菜品
     * @param type 菜品类别
     * @param status 菜品状态
     * @param name 菜品名称
     * @returns
     */
    async listByTypeAndStatus(type?: string, status?: number,name?: string){
        const ro = new RequestOption()
        const params: any = {
            action : 'listDishesByTypeAndStatus'
        }
        if (type) params.type = type
        if (status !== undefined) params.status = status
        if (name) params.name = name
        return await tr.get(getActToolUrl(), params, ro)
    }

    /**
     * 列出所有菜品（别名方法）
     * @returns
     */
    async listAllDishes(){
        return await this.listAll()
    }

    /**
     * 删除某个菜品
     * @returns
     */
    async deleteDish(dishId:number){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'deleteDish',
            Id : dishId
        }, ro)
    }
    /**
     * 新增某个菜品
     * @returns
     */
    async saveDish(dish:any){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'saveDish',
            name : dish.name,
            type : dish.type,
            price : dish.price * 100,
            desc : dish.desc,
            status : dish.status
        }, ro)
    }
    /**
     * 修改某个菜品
     * @returns
     */
    async updateDish(dish:any){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'updateDish',
            Id : dish.Id,
            name : dish.name,
            price : dish.price * 100,
            desc : dish.desc,
            status : dish.status
        }, ro)
    }
    /**
     * 修改某个菜品状态
     * @returns
     */
    async updateDishStatus(dishId:number, status:number){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'updateDishStatus',
            Id : dishId,
            status : status
        }, ro)
    }
    /**
     * 你好
     * @returns
     */
    async helloworld(){
        const ro = new RequestOption()
        return await tr.get(getActToolUrl(), {
            action : 'helloworld',
        }, ro)
    }
}
